
#include "led.h"
#include "usart.h"
#include "system.h"
#include "common.h"
#include "magnetic_encoder.h"

int main(void)
{
  SystemInit();

  rccInit();
  nvicInit();
  //ioInit();
  //iwdgInit();

  MagneticEncoder magnetic_encoder;

  while (true) {
    float angle;
    angle = magnetic_encoder.getAngle();
    int a;
    a = 1;
    a += 1;
    a += 2;
  }

/*
  Controller<CONTROLLER_USART> controller;
  Led<GPIOB_BASE, GPIO_Pin_8> led;

  // Main
  Command controller_command;
  while (true) {
    // Reload watchdog timer
    IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
    IWDG_ReloadCounter();
    IWDG_WriteAccessCmd(IWDG_WriteAccess_Disable);

    if (controller.recv(&controller_command)) {
      switch(controller_command.id) {
        case CONTROLLER_RESET:
          break;
  
        case CONTROLLER_IDENTIFIER:
          controller_command.payload = "BOOTLOADER";
          break;
        
        case CONTROLLER_BOOT_MAIN:
          break;
        
        default:
          break;
      }
    }

    // Do periodic tasks
    led.on();
    controller.work();
    led.off();
  }
*/
  return 0;
}

extern "C" {
  void HardFault_Handler(void)
  {
    // Loop until WDT reset
    while (1);
  }
}
